package qf.service.serviceImpl;

import org.apache.commons.dbutils.QueryRunner;
import qf.dao.UserDao;
import qf.pojo.User;
import qf.service.AdminService;
import qf.utils.Constants;
import qf.utils.DBUtil;
import qf.utils.MD5Utils;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.service
 * @Description:
 * @Date 2022/5/21 15:05
 */
public class AdminServiceImpl implements AdminService {
    private UserDao userdao;

    public AdminServiceImpl(UserDao userdao) {
        this.userdao = userdao;
    }
    @Override
    public User findAdmin(String username, String password) {
        System.out.println(username);
        System.out.println(password);
        User user = userdao.findUsername(username);
        //判断user是否为空
        if (user == null) {
            return null;
        }
        //是否为激活后的用户
        if (!Constants.USER_ACTIVE.equals(user.getStatus())) {
            return null;
        }
        //判断输入的密码是否与查到用户的密码是否一样
        String password1 = MD5Utils.md5(password);
        if (!user.getPassword().equals(password1)) {
            return null;
        }
        //判断是否为管理员
        if (user.getRole() == Constants.ROLE_ADMIN) {
            return user;
        }
        //其他情况
        return  null;
    }


}